/*
 *  MW.cpp
 *  T3nsors
 *
 *  Created by Michael Barriault on 09-10-27.
 *  Copyright 2010 University of Guelph. All rights reserved.
 *
 */

#include <iostream>
#include <ctime>
#include <cstdlib>
#include "MW.h"

MW::MW() {
	return;
}

MW::MW(Domain iO, double iK, double iepsilon, double iJ, Comm *iBadge) {
	O = iO;
	Badge = iBadge;
	Badge->PrintStatus("Allocating constants");
	x = Vector(O,3,"x");
	epsilon = iepsilon;
	K = iK;
	J = iJ;
	damp = 1;
	c = 0.0;
	stopit = false;
	Phi = Scalar(O,"Phi");
	Psi = Scalar(O,"Psi");
	E = Vector(O,3,"E");
	B = Vector(O,3,"B");

	FOR(i,O[0]) FOR(j,O[1]) FOR(k,O[2]) {
		x(0,i,j,k) = O.min(0) + i*O.d(0);
		x(1,i,j,k) = O.min(1) + j*O.d(1);
		x(2,i,j,k) = O.min(2) + k*O.d(2);
	}

	time_t now;
	struct tm *timeinfo;
	time(&now);
	timeinfo = localtime(&now);
	char str[15];
	strftime(str,15,"run%y%m%d%H%M",timeinfo);
	id = (std::string)str;
	std::string cmd = (string)"mkdir " + id + " 2> /dev/null";
	while ( system(cmd.c_str()) ) {
		for ( int i=12; i>0; i-- ) {
			str[i]++;
			if ( str[i] < 58 ) break;
			else str[i] -= 10;
		}
		id = (std::string)str;
		cmd = (string)"mkdir " + id + " 2> /dev/null";
	}
}

MW::~MW(void) {
	Badge->PrintStatus("Deallocating...");
	delete Badge;
}

